import request from '../utils/request';

// 用户相关
export const login = (data) => request.post('/users?method=login', data);
export const getUserList = () => request.get('/users?method=getAllUsers');
export const updateUser = (data) => request.post('/users?method=updateUser', data);
export const addUser = (data) => request.post('/users?method=addUser', data);

// 资产相关
export const getAssetList = () => request.get('/assets?method=getAllAssets');
export const createAsset = (data) => request.post('/assets?method=addAsset', data);
export const updateAsset = (id, data) => request.put(`/assets/${id}?method=updateAsset`, data);
export const permitUpdate = (id, data) => request.put(`/assets/${id}?method=permitUpdate`, data);
export const deleteAsset = (id) => request.delete(`/assets?method=deleteAsset&assetId=${id}`);

// 借用相关
export const getBorrowList = () => request.get('/borrows?method=getAllBorrows');
export const createBorrow = (data) => request.post('/borrows?method=addBorrow', data);
export const updateBorrow = (borrowId, data) => request.put(`/borrows/${borrowId}?method=updateBorrow`, data);
export const updateBorrowStatus = (borrowId, data) => request.put(`/borrows/${borrowId}?method=updateBorrowStatus`, data);
export const returnAsset = (id) => request.put(`/borrows/${id}/return?method=returnAsset`);
export const deleteBorrow = (borrowId) => request.delete(`/borrows?method=deleteBorrow&borrowId=${borrowId}`);

// 部门相关
export const getDepartmentList = () => request.get('/departments?method=getAllDepartments');
export const createDepartment = (data) => request.post('/departments?method=addDepartment', data);
export const updateDepartment = (id, data) => request.put(`/departments?method=updateDepartment`, {
    ...data,
    depId: id
});
export const deleteDepartment = (id) => request.delete(`/departments?method=deleteDepartment&depId=${id}`);

// 文件上传相关
export const uploadFile = (formData) => request.post('/files?method=uploadFile', formData, {
    headers: {
        'Content-Type': 'multipart/form-data'
    }
});

export const downloadFile = (fileName) => request.get(`/files?method=downloadFile&fileName=${fileName}`, {
    responseType: 'blob'
});

export const getFileUrl = (fileName) => request.get(`/files?method=getFileUrl&fileName=${fileName}`);

export const deleteFile = (fileName) => request.get(`/files?method=deleteFile&fileName=${fileName}`);

// 获取文件列表
export const getFileList = () => request.get('/files?method=getAllFiles');

// 获取部门资产使用数据
export const getAssetUsage = (params) => request.get(`/borrows?method=getUsageStats&month=${params.month}&depId=${params.depId}`); 